home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * clipsound -
- * display and extract a sub sample from a aiff file
- *
- * Paul Haeberli - 1991
- */
- #include "stdio.h"
- #include "gl.h"
- #include "device.h"
- #include "sample.h"
-
- float fgetmousex();
-
- printdoc()
- {
- printf("\nuse the left mouse button to select a range of the sample\n");
- printf("click the middle mouse button to play the selection\n");
- printf("use the menu to zoom in on the stuff you've selected\n");
- printf("or to write out the selected sample\n\n");
- }
-
- int pos1, pos2;
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- sample *s, *subsamp;
- short val;
- int i, opos1, menu;
- float fdelta;
-
- subsamp = 0;
- if(argc<2) {
- fprintf(stderr,"usage: clipsample in.a\n");
- exit(1);
- }
- printdoc();
- winopen("aiff");
- RGBmode();
- gconfig();
-
- cpack(0x808080);
- clear();
-
- s = readsample(argv[1]);
- expandsample(s);
- printsample(s);
- drawit(s);
- qdevice(LEFTMOUSE);
- qdevice(MIDDLEMOUSE);
- qdevice(RIGHTMOUSE);
- qdevice(ESCKEY);
- qdevice(UPARROWKEY);
- qdevice(DOWNARROWKEY);
- menu = defpup("clipsound %t|zoom into selection|write sample");
- fdelta = 16000;
- while(1) {
- switch(qread(&val)) {
- case ESCKEY:
- exit(1);
- break;
- case REDRAW:
- drawit(s);
- break;
- case LEFTMOUSE:
- if(val) {
- if(myshiftdown()) {
- while(getbutton(LEFTMOUSE)) {
- pos1 = s->nsamples*fgetmousex()/s->nchannels;
- pos1 = pos1-fdelta/2;
- pos2 = pos1+fdelta/2;
- drawselection(s,pos1,pos2);
- if(subsamp)
- freesample(subsamp);
- subsamp = subsample(s,2*pos1,2*pos2);
- playsample(subsamp);
- flushsample();
- }
- } else {
- pos1 = s->nsamples*fgetmousex()/s->nchannels;
- while(getbutton(LEFTMOUSE)) {
- pos2 = s->nsamples*fgetmousex()/s->nchannels;
- drawselection(s,pos1,pos2);
- sginap(5);
- }
- printf("%d %d\n",pos1,pos2);
- if(subsamp)
- freesample(subsamp);
- if(pos2 == pos1)
- pos2 = pos1+1;
- subsamp = subsample(s,2*pos1,2*pos2);
- playsample(subsamp);
- }
- }
- break;
- case MIDDLEMOUSE:
- if(val) {
- if(subsamp)
- playsample(subsamp);
- }
- break;
- case RIGHTMOUSE:
- if(val) {
- switch(dopup(menu)) {
- case 1:
- if(subsamp) {
- freesample(s);
- s = subsamp;
- subsamp = 0;
- pos1 = pos2 = 0;
- drawit(s);
- }
- break;
- case 2:
- if(subsamp)
- writesample(subsamp,"clip.a");
- else
- writesample(s,"clip.a");
- printf("sample written to clip.a\n");
- break;
- }
- }
- break;
- case UPARROWKEY:
- if(val)
- fdelta = fdelta*1.41;
- break;
- case DOWNARROWKEY:
- if(val)
- fdelta = fdelta/1.41;
- break;
- }
- }
- }
-
- drawit(s)
- sample *s;
- {
- reshapeviewport();
- drawsamples(s);
- drawselection(s,pos1,pos2);
- }
-
- drawsamples(s)
- sample *s;
- {
- int i, nframes;
- short *sptr;
- int ibuf[2];
- int inc;
-
- nframes = s->nsamples/2.0;
- inc = 1+(nframes/2000.0);
- printf("inc is %d nframes is %d\n",inc,nframes);
- ortho2(0.0,(float)nframes,-40000.0,40000.0);
- cpack(0x808080);
- clear();
-
- sptr = s->data;
- for(i=0; i<nframes; i+=inc) {
- cpack(0x0000ff);
- move2i(i,0);
- draw2i(i,sptr[0]);
- cpack(0x00ff00);
- move2i(i,0);
- draw2i(i,sptr[1]);
- sptr += 2*inc;
- }
- }
-
- drawselection(s,pos1,pos2)
- sample *s;
- int pos1,pos2;
- {
- int nframes;
-
- nframes = s->nsamples/2.0;
- cpack(0x808080);
- rectfi(0,-40000,nframes,-40000+1000);
- cpack(0x000000);
- rectfi(pos1,-40000,pos2,-40000+1000);
- }
-
- myshiftdown()
- {
- if(getbutton(LEFTSHIFTKEY) || getbutton(RIGHTSHIFTKEY))
- return 1;
- else
- return 0;
- }
-